package com.sali.Tree;

/**
 * @author sali
 * @date 2025/5/5 16:13
 */
public class LeetCode_108 {

    public TreeNode sortedArrayToBST(int[] nums) {
        return mySolve(nums, 0, nums.length - 1);
    }


    private TreeNode mySolve(int[] nums, int left, int right) {
        if (left > right) return null;

        if (right - left == 0) {
            return new TreeNode(nums[left]);
        }

        int midVal = left + (right - left) / 2;
        TreeNode cur = new TreeNode(nums[midVal]);
        cur.left = mySolve(nums, left, midVal - 1);
        cur.right = mySolve(nums, midVal + 1, right);

        return cur;
    }

}
